package com.fanhao.dllo.justforyou.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.TabHost;

import com.fanhao.dllo.justforyou.R;
import com.fanhao.dllo.justforyou.fragment.JokeFragment;
import com.fanhao.dllo.justforyou.fragment.MovieFragment;
import com.fanhao.dllo.justforyou.fragment.NewsFragment;
import com.fanhao.dllo.justforyou.fragment.FoodFragment;
import com.fanhao.dllo.justforyou.fragment.YoursFragment;

/**
 * Created by dllo on 15/10/23.
 */
public class HomeActivity extends FragmentActivity{

    private TabHost mHost;
    private FragmentManager fm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);


        initView();
        initFragment();

    }
 // 设置tabwidget
    public void initView() {
        mHost = (TabHost) findViewById(android.R.id.tabhost);
        mHost.setup();

        TabHost.TabSpec spec0 = mHost.newTabSpec("spec0");
        View tabView0 = getLayoutInflater()
                .inflate(R.layout.tabwidget_news, null);
        spec0.setIndicator(tabView0);
        spec0.setContent(R.id.newsView);
        mHost.addTab(spec0);

        TabHost.TabSpec spec1 = mHost.newTabSpec("spec1");
        View tabView1 = getLayoutInflater()
                .inflate(R.layout.tabwidget_food, null);
        spec1.setIndicator(tabView1);
        spec1.setContent(R.id.stroyView);
        mHost.addTab(spec1);

        TabHost.TabSpec spec2 = mHost.newTabSpec("spec2");
        View tabView2 = getLayoutInflater()
                .inflate(R.layout.tabwidget_joke,null);
        spec2.setIndicator(tabView2);
        spec2.setContent(R.id.jokeView);
        mHost.addTab(spec2);

//        TabHost.TabSpec spec3 = mHost.newTabSpec("spec3");
//        View tabView3 = getLayoutInflater()
//                .inflate(R.layout.tabwidget_movie,null);
//        spec3.setIndicator(tabView3);
//        spec3.setContent(R.id.movieView);
//        mHost.addTab(spec3);

        TabHost.TabSpec spec4 = mHost.newTabSpec("spec4");
        View tabView4 = getLayoutInflater()
                .inflate(R.layout.tabwidget_person,null);
        spec4.setIndicator(tabView4);
        spec4.setContent(R.id.yoursView);
        mHost.addTab(spec4);

    }

    public void initFragment() {
        fm = getSupportFragmentManager();

        android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.newsView, new NewsFragment());
        ft.replace(R.id.stroyView, new FoodFragment());
        ft.replace(R.id.jokeView, new JokeFragment());
//        ft.replace(R.id.movieView, new MovieFragment());
        ft.replace(R.id.yoursView, new YoursFragment());

        ft.commit();


    }



}
